package com.emergency.evaluate.dao;


import com.emergency.evaluate.domain.Indicator;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.util.List;

/**
 * Created by Administrator on 2020/3/10.
 */
public interface IndicatorDao extends JpaRepository<Indicator,Integer>,JpaSpecificationExecutor<Indicator> {
   //根据指标类型选择指标
    @Query(value = "select i from Indicator i where i.kind=:kind")
    List<Indicator> findAllByKindEquals(@Param ("kind") Integer kind);
    //根据指标id 选择指标
    @Query(value = "select i from Indicator i where i.id=:id")
    Indicator findAllById(@Param ("id") Long id);
    @Query(value = "select i from Indicator i where i.id=:id")
    List<Indicator> findById(@Param ("id") Long id);
   //按照查询条件实现分页查询
    Page<Indicator> findAll(Specification <Indicator> spec, Pageable pageable);

    //根据指标ID删除指标库的指标
    @Transactional
    @Modifying
    @Query(value = "delete from Indicator i where i.id=:id")
    void deleteById(@Param ("id") Long id);
}
